<template>
	<view class="ys">
		<view class="top">
			<view class="search">
				<image src="@/static/index/ss.png" mode=""></image>
				<input type="text" placeholder="搜索店铺" placeholder-style="color:#B8B9BD" v-model="title"
					@confirm="search" @input="isEmpty" />
			</view>
		</view>
		<view class="list" v-if="list.length != 0">
			<view class="item" v-for="(item,index) in list" :key="index"
				@click="toPage('./transfer?type='+item.type+'&id='+item.id)">
				<image :src="item.logo | getImg" mode=""></image>
				<view class="info">
					<view class="name">
						{{item.title}}
					</view>
					<view class="phone">
						店主姓名: {{item.name}}
					</view>
					<view class="phone">
						联系方式: <text @click="callPhone(item.phone)">拨打电话</text>
					</view>
					<view class="phone">
						地址: {{item.shop_address}}
					</view>
					<view class="phone">
						距离: {{item.distance}}
					</view>
				</view>
			</view>
		</view>
		<view class="no-list" v-else>
			- 暂无数据 -
		</view>
	</view>
</template>

<script>
	import {
		SShop
	} from "@/api/api.js"
	export default {
		data() {
			return {
				list: [],
				page: 1,
				class: '', //店铺分类
				type: '', //店铺类型 积分店铺 余额店铺
				title: ''
			}
		},
		onLoad(e) {
			if (e.type) {
				this.type = e.type
			}
			if (e.class) {
				this.class = e.class
			}
			this.SShop()
		},
		onReachBottom() {
			if (this.page < this.last_page) {
				this.page++
				this.SShop()
			}
		},
		methods: {
			callPhone(i) {
				uni.makePhoneCall({
					phoneNumber: i
				})
			},
			isEmpty() {
				if (this.title == '') {
					this.search()
				}
			},
			search() {
				this.clear()
				this.SShop()
			},
			clear() {
				this.page = 1
				this.last_page = 1
				this.list = []
			},
			choose(item) {
				ChooseShop({
					recommend_code: item.recommend_code
				}).then(res => {
					uni.$showMsg(res.message)
					if (res.status == 1) {
						setTimeout(() => {
							uni.redirectTo({
								url: './childshop'
							})
						}, 500)
					}
				})
			},
			SShop() {
				SShop({
					page: this.page,
					type: this.type,
					class: this.class,
					title: this.title
				}).then(res => {
					if (res.status == 1) {
						this.list = this.list.concat(res.data.List.data)
						this.last_page = res.data.List.last_page
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.top {
		background: #fff;
		padding: 10px 0;
		position: sticky;
		top: 0px;
		/* #ifdef H5 */
		top: 44px;
		/* #endif */
		z-index: 99;

		.search {
			position: relative;
			width: 90%;
			background: #F5F5F5;
			border-radius: 20px;
			margin: 0px auto;
			display: flex;
			align-items: center;
			padding: 0 10px;
			box-sizing: border-box;
			padding-left: 20px;

			image {
				width: 15px;
				height: 15px;
			}

			input {
				width: 80%;
				margin-left: 10px;
				line-height: 35px;
				height: 35px;
				color: #000;
				font-size: 14px;
			}


		}

	}

	.list {
		padding: 10px;

		.item {
			display: flex;
			background: #fff;
			border-radius: 5px;
			padding: 6px 10px;
			box-sizing: border-box;
			align-items: center;
			margin-bottom: 10px;

			image {
				width: 80px;
				height: 80px;

			}

			.info {
				flex: 1;
				padding: 0 15px;
				box-sizing: border-box;

				.name {
					font-size: 14px;
					margin-bottom: 3px;
					font-weight: bold;
				}

				.phone {
					font-size: 12px;
					color: #777;
					margin-bottom: 3px;
				}
			}

			button {
				width: 70px;
				height: 35px;
				line-height: 35px;
				font-size: 13px;
				background: #E1ECFE;
				color: #6b7490;
				font-weight: bold;
			}
		}
	}
</style>